package cn.com.roy.thread.t3_2_2.jointest2;

public class Test {

    public static void main(String[] args) {
        Thread myThread = new Thread(new Runnable() {
            public void run() {
                int secondValue =  (int) (Math.random() * 10000);
                System.out.println(secondValue);
                try {
                    Thread.sleep(secondValue);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        myThread.start();

        try {
            myThread.join();  //join的作用是使主线程无限期阻塞，等子线程销毁之后在继续执行主线程之后的代码;
                              // join的原理是在内部使用wait等待，而synchronized关键是使用的对象监视器原理做同步

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(1);
        System.out.println(2);
        System.out.println(3);
    }

}
